////////////////////////////////////////////////////////////////////////////////
/// Midnight Circus 2007
////////////////////////////////////////////////////////////////////////////////

using System.Collections.Generic;

namespace GatherTogether
{
    namespace GatherItems
    {
        /// <summary>
        /// Class to describe the gathered items from a specific continent. These
        /// continents include Kalimdor, Eastern Kingdoms, and Outlands.
        /// </summary>
        class Continent : IEnumerable<Area>
        {
            protected List<Area> m_areas = new List<Area>();

            public IEnumerator<Area> GetEnumerator()
            {
                foreach (Area area in m_areas)
                {
                    yield return area;
                }
            }

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }

            public void Add(Area area)
            {
                m_areas.Add(area);
            }

            public void Merge(Continent otherContinent)
            {
                m_areas.Sort();
                foreach (Area area in otherContinent.m_areas)
                {
                    int index = m_areas.BinarySearch(area);
                    if (index < 0)
                        m_areas.Add(area);
                    else
                        m_areas[index].Merge(area);
                }
            }
        }
    }
}
